package com.neusoft.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.po.Cart;

@Mapper
public interface CartMapper {
	
	@Select("select * from cart where businessId=#{businessId} and userId=#{userId} order by foodId")
	public List<Cart> listCart(Cart cart);
	
	@Insert("insert into cart (foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},1)")
	@Options(useGeneratedKeys=true,keyProperty="cartId",keyColumn="cartId")
	public int saveCart(Cart cart);
	
	@Update("update cart set quantity=#{quantity} where foodId=#{foodId} and businessId=#{businessId} and userId=#{userId}")
	public int updateCart(Cart cart);
	
	@Delete("delete from cart where foodId=#{foodId} and businessId=#{businessId} and userId=#{userId}")
	public int removeCart(Cart cart);
}
